 var isUpProductBuy = false;
var isDownProductBuy = false;
//js去掉空格
function trim(str){ 
	return  str.replace(/^\s+|\s+$/g,"");
}
function trimForm()
{    
	var  orderNo=$('#orderNo').val();
	    
	var re = /^[1-9]+[0-9]*]*$/;
	if(orderNo.length!=0){
		if (!re.test(orderNo))  
		{  
			 
			 
			layer.msg('订单号必须为正整数！',{icon:1,time:1000},function(){

			});
			document.getElementById("orderNo").value="";
			return false;   
		}
		if(orderNo.length>17){
			 
			layer.msg('订单号长度不能大于17位！',{icon:1,time:1000},function(){

			});
			 
			return false;	
		}
	}
	if(orderNo==null || orderNo==""){
	 
		layer.msg('订单号不能为空！',{icon:1,time:1000},function(){

		});
		document.getElementById("orderNo").value="";
		return false
	}				
	document.getElementById('orderNo').value=trim(document.getElementById('orderNo').value);			
		 
	var sel = $("#state").val();
		if(sel=="-1"){
			alert("请选择订单类别");
			return false;
		}
		
		
		
//根据订单号  判断选择的订单是普通1 秒杀3  团购2
	var  orderNo=$('#orderNo').val();
	
	var orderNoFirst = orderNo.charAt(0);
	$("#state").attr("value",orderNoFirst);
 	 	
	return true;		 		
}
function search() {
	 
	if(trimForm()){
		$(query_order_form).submit();
	};
}
function toIsEmpty() {
	$("#startDate").val("");
	$("#endDate").val("");
	$("#state").val("");	
	$("#orderNo").val("");
	//$('#query_order')[0].reset();
}
var flag =true;
function comms1(){
	//提交必须有选中项
	var ids = "";
     $("[id^='chk']:checked").each(function(){
		  var id = $(this).attr("value");
		  ids += id + ",";         
	 });
     var orderNo = $("#orderNo").val();
     if(orderNo==null || orderNo==""){
  		layer.msg('请先输入需要查询的订单号！',{icon:1,time:1000},function(){

		});
  		document.getElementById("orderNo").value="";
  		
  		return false
  	}
	 if(ids == ""){
		layer.msg('无选中退还商品！',{icon:1,time:1000},function(){

		});
		 return false;
	 }
		 
	//退还理由不能为空
	var c_remark = $("#c_remark").val();
	if(c_remark==null || c_remark==""){
		 
		layer.msg('退单理由不能为空！',{icon:1,time:1000},function(){

		});

		return false;
	}
	if(trim(c_remark)==""){
	 
		layer.msg('退还理由格式输入有误！',{icon:1,time:1000},function(){

		});
		return false;
		
	}
	
//提交订单
if(flag){
	/*$("#commsId1").hide();*/
	$("#cancleOrder").submit(); 				
}else{
	alert(message);
}
	
	
}
 
var message = "";
function check_n(nId){
	var buyNum_begin = $("#"+nId).val();
	var buyNum_end = $("input[name='"+nId+"']").val();
	
	var buyNum_begin_int = parseInt(buyNum_begin);
	var buyNum_end_int = parseInt(buyNum_end);
	if(buyNum_end==null||buyNum_end==""){
		alert("商品数量不能为空");
		message = "商品数量不能为空";
		flag = false;
		return ;
	}else{
		flag = true;
	}
	if(buyNum_end_int < 0){
		alert("商品数量不能小于0");
		message = "商品数量不能小于0";
		flag = false;
		return ;
	}else{
		flag = true;
	}
	if(buyNum_end_int > buyNum_begin_int){
		alert("商品数量不能大于预定的商品数量");
		message = "商品数量不能大于预定的商品数量";
		flag = false;
		return ;
	}else{
		flag = true;				
	}
	
}
function check_m(mId){
	var mileage_begin = $("#"+mId).val();
	var mileage_end = $("input[name='"+mId+"']").val();
	
	var mileage_begin_int = parseInt(mileage_begin);
	var mileage_end_int = parseInt(mileage_end);
	if(mileage_end==null||mileage_end==""){
		alert("里程不能为空");
		message="里程不能为空";
		flag = false;
		return ;
	}else{
		flag = true;
	}
	if(mileage_end_int < 0){
		alert("里程不能小于0");
		message="里程不能小于0";
		flag=false;
		return ;
	}else{
		flag = true;
	}
	if(mileage_end_int > mileage_begin_int){
		alert("退换里程不能大于商品的里程价格");
		message="退换里程不能大于商品的里程价格";
		flag = false;
		return ;
	}else{
		flag = true;				
	}
	
}

//全选按钮事件
	$("#chkAll2").click(function(){
   			
						if($("#chkAll2").attr("checked")){
							$("input[name='chk']").each(function(){
								this.checked=true;
							});
						}else{
							$("input[name='chk']").each(function(){
								this.checked=false;
							});
						}
			      });

	if("${msg}" == "noPay") {
		alert("订单尚未支付"); 
		}

 